<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>AUI快速完成布局</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <style type="text/css">
        .aui-list-item.wechat-top {
            background-color: #f3f3f7;
        }
        .aui-list .wechat-avatar {
            width:3rem;
        }
        .wechat-avatar .aui-row-padded {
            background-color: #dddee0;
            padding: 0.1rem;
            border-radius: 0.2rem;
            margin-left: -0.05rem;
            margin-right: -0.05rem;
        }
        .wechat-avatar .aui-row-padded [class*=aui-col-xs-] {
            padding: 0.05rem;
        }
        .wechat-avatar,
        .wechat-avatar > img {
            border-radius:0.2rem;
        }
    </style>
</head>
<body>
    <div class="aui-content aui-margin-b-15">
        <ul class="aui-list aui-media-list" id="work-list">

            <!--<li class="aui-list-item aui-list-item-middle">
                <div class="aui-media-list-item-inner">
                    <div class="aui-list-item-media wechat-avatar">
                        <div class="aui-badge">9</div>
                        <img src="../image/demo5.png" />
                    </div>
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-text">
                            <div class="aui-list-item-title">admin 报销 (2017-07-27 10:30:18)</div>
                            <div class="aui-list-item-right">星期一</div>
                        </div>
                        <div class="aui-list-item-text aui-font-size-12">
                            admin
                        </div>
                    </div>
                </div>
            </li>-->

        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript" src="../script/aui-toast.js" ></script>
<script type="text/javascript">
var toast = new auiToast();
apiready = function(){
     $api.setStorage("work_index", 0);
     load();
     //上拉翻页
     api.addEventListener({
         name : 'scrolltobottom'
     }, function(ret, err) {
         $api.setStorage("work_index", $api.getStorage("work_index") - 0 + 1);
         load();
     });
 }

//资讯列表加载
 function load(first, index2) {
     api.showProgress({
        style: 'default',
        animationType: 'fade',
        title: '拼命加载中...',
        text: '不如喝茶去...',
        modal: false
     });
     var index = $api.getStorage("work_index");
     var username = $api.getStorage("username");
     var work_status = api.pageParam.work_status;
     var url = ServeUrl + "m=Workflow&a=workData&pageIndex=" + index + "&pageCount=15&username="+username+"&work_status="+work_status;
     ajaxRequest(url, 'get', '', function(data) {
         dealWithHtml(data, first, index);
     });

 }

 function ajaxRequest(url, method, datas, callBack) {
     api.ajax({
         url : url,
         method : method,
         cache : false,
         timeout : 30,
         dataType : 'json',
         data : {
             values : datas
         }
     }, function(ret, err) {
         if (ret.data) {
             callBack(ret, err);
         } else {
             //alert("没有更多的用户！");
             toast.success({
                 title:"已加载所有工作",
                 duration:2000
             });
             api.hideProgress();
         }
     });
 }

//字符串拼接
 function dealWithHtml(data, first, index) {
     //alert(JSON.stringify(data));
     var htm = '';
     for (var i = 0; i < data.data.length; i++) {
        htm += '<li class="aui-list-item aui-list-item-middle" onclick="openWin('+data.data[i].id+')">'
        htm += '<div class="aui-media-list-item-inner">'
        htm += '<div class="aui-list-item-media wechat-avatar">'
        htm += '<img src="../image/demo1.png" />'
        htm += '</div>'
        htm += '<div class="aui-list-item-inner">'
        htm += '<div class="aui-list-item-text" >'
        htm += '<div class="aui-list-item-title">'+data.data[i].working_name+'</div>'
        htm += '</div>'
        htm += '<div class="aui-list-item-text aui-font-size-12">'+data.data[i].applicant
        htm += '<div class="aui-list-item-right">'+data.data[i].create_time+'</div>'
        htm += '</div>'
        htm += '</div>'
        htm += '</div>'
        htm += '</li>'
     }
    $("#work-list").append(htm);
    api.hideProgress();

 }

  function openWin(id) {

    //  alert(cn_name);
      api.openWin({
          name: "workform_edit_win",
          url: 'workform_edit_win.html',
          pageParam: {
              id: id
          }
      });
  }
</script>
</html>
